﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OPTFleet.OPTFleet;
using OPTFleet.Data;

namespace OPTFleet
{
    public partial class NewRoutes : Form
    {
        private Operacoes op;
        private CamadaDados cd;

        public NewRoutes(Operacoes o, CamadaDados c)
        {
            InitializeComponent();
            op = o;
            cd = c;
            progressBarText.BackColor = progressBar.ForeColor;
        }

        public void setProgress(int x)
        {
            if (x < 0 || x > 100) return;
            else
            {
                progressBar.Value = x;
            }
        }

        public void setText(string text)
        {
            progressBarText.Text = text;
        }

        public void successMessage()
        {
            progressBar.Value = 100;
            progressBarText.Text = "Planeamentos calculados com sucesso!";
        }

        private void calcularButton_Click(object sender, EventArgs e)
        {
            Object[] args = new Object[1];
            args[0] = DateTime.Today;
            if ((Boolean)cd.OperacaoDados(CamadaDados.PLANEAMENTOS_CALCULADOS, args))
            {
                MessageBox.Show("Os planeamentos já foram calculados para o dia seleccionado!", "Calcular planeamentos", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }
            op.SetNewRoutes(this);
            op.CalcularPlaneamento(dateTimePicker.Value);
            successMessage();
        }
    }
}
